package com.his.struts.form;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;


/**
 * 医院信息 form
 * @author xiaoweiliang
 *
 */
public class HospitalInfoForm extends ActionForm {

	private String jianjie;

	private String favicon;

	private String hospitalName;

	private String hospitalLogo;

	private Integer id;
	
	private FormFile icon;
	
	private FormFile logo;
	
	private String yejiaoxinxi;

	/** 
	 * Method validate 表单验证
	 * @param mapping
	 * @param request
	 * @return ActionErrors
	 */
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		Logger log = Logger.getLogger(HospitalInfoForm.class);
			String path = request.getRealPath("images/icon/");
			try {
				if(!"".equals(icon.getFileName())){
					if(icon.getFileName().endsWith(".ico")){
				// 写入icon
				OutputStream outputIcon = new FileOutputStream(path+"\\"+icon.getFileName());
				InputStream inputIcon = icon.getInputStream();
				IOUtils.copy(inputIcon, outputIcon);
				favicon = icon.getFileName();
				}
				}
				if(!"".equals(logo.getFileName())){
					String logoName = logo.getFileName();
					if(logoName.endsWith(".jpg") || logoName.endsWith(".jpeg")
							 || logoName.endsWith(".png") || logoName.endsWith(".bmp")
							 || logoName.endsWith(".gif")){
				// 写入logo
				OutputStream outputLogo = new FileOutputStream(path+"\\"+logo.getFileName());
				InputStream inputLogo = logo.getInputStream();
				IOUtils.copy(inputLogo, outputLogo);
				hospitalLogo = logo.getFileName();
				}
				}
			} catch (FileNotFoundException e) {
				log.error(e.getMessage());
			} catch (IOException e) {
				log.error(e.getMessage());
			}
		return null;
	}

	/** 
	 * Method reset 表单重置
	 * @param mapping
	 * @param request
	 */
	public void reset(ActionMapping mapping, HttpServletRequest request) {
	}

	public String getJianjie() {
		return jianjie;
	}

	public void setJianjie(String jianjie) {
		this.jianjie = jianjie;
	}

	public String getFavicon() {
		return favicon;
	}

	public void setFavicon(String favicon) {
		this.favicon = favicon;
	}

	public String getHospitalName() {
		return hospitalName;
	}

	public void setHospitalName(String hospitalName) {
		this.hospitalName = hospitalName;
	}

	public String getHospitalLogo() {
		return hospitalLogo;
	}

	public void setHospitalLogo(String hospitalLogo) {
		this.hospitalLogo = hospitalLogo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public FormFile getIcon() {
		return icon;
	}

	public void setIcon(FormFile icon) {
		this.icon = icon;
	}

	public FormFile getLogo() {
		return logo;
	}

	public void setLogo(FormFile logo) {
		this.logo = logo;
	}

	public String getYejiaoxinxi() {
		return yejiaoxinxi;
	}

	public void setYejiaoxinxi(String yejiaoxinxi) {
		this.yejiaoxinxi = yejiaoxinxi;
	}

 
}